package com.Object;

public class ObjectDemo1 {
    public static void main(String[] args) {
        //创建两个“学生对象”并为它们的属性赋值，
        // 并能比较两个对象的所有属性值是否完全相等
        Student student1 = new Student("张三","男",24);
        Student student2 = new Student("小红","女",20);
        System.out.println(student1.equals(student2));
    }

}
class Student{
   //请按标准格式定义一个“学生类”，它有三个属性：姓名、性别、年龄
    private String name;
    private String sex;
    private int age;

    public Student() {
    }

    public Student(String name, String sex, int age) {
        this.name = name;
        this.sex = sex;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Student student = (Student) o;

        if (age != student.age) return false;
        if (name != null ? !name.equals(student.name) : student.name != null) return false;
        return sex != null ? sex.equals(student.sex) : student.sex == null;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", sex='" + sex + '\'' +
                ", age=" + age +
                '}';
    }
}